package test;

/**
 * @Author:zimmor
 * @Date: 2022/7/26 23:05
 * @Description
 * @version: 1.0.0
 */

public class demo7 {
    public static void main(String[] args) {
        String s = perm2String(8);
        System.out.println("s = " + s);
    }
    public static String perm2String(int perm) {
        StringBuffer sb = new StringBuffer("---");
        if (isReadable(perm)) {
            sb.replace(0, 1, "R");
        }

        if (isWriteable(perm)) {
            sb.replace(1, 2, "W");
        }

        if (isInherited(perm)) {
            sb.replace(2, 3, "X");
        }

        return sb.toString();
    }

    public static boolean isReadable(int perm) {
        return (perm & 4) == 4;
    }

    public static boolean isWriteable(int perm) {
        return (perm & 2) == 2;
    }

    public static boolean isInherited(int perm) {
        return (perm & 1) == 1;
    }
}
